/**
 * Copyright 北京彩通农旗资讯有限公司 All rights reserved.
 * 北京彩通农旗资讯有限公司 专有/保密源代码,未经许可禁止任何人通过任何* 渠道使用、修改源代码.
 */
package com.xspace.android.xafcommon.view.dialog;


import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;

import com.xspace.android.xafcommon.R;


/**
 * 对话框辅助类
 */
public class DialogHelp {

    /***
     * 获取一个dialog
     *
     * @param context
     * @return
     */
    public static AlertDialog.Builder getDialog(Context context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        return builder;
    }

    //    public static WebviewOperationDialog.Builder getWebViewDialog(Context mContext, WebviewOperationDialog
    // .IOperateClickListener listener) {
    //        WebviewOperationDialog.Builder builder = new WebviewOperationDialog.Builder(mContext);
    //        builder.setListener(listener);
    //        return builder;
    //    }

    /**
     * 获取确认对话框，left 为取消
     *
     * @param context
     * @param message
     * @param leftTxt
     * @param rightTxt
     * @param rightOnClickListener
     * @param leftOnClickListener
     * @return
     */
    public static ConfirmDialog.Builder getConfirmDialog(Context context, String title, String message, String
            leftTxt, String rightTxt,
                                                         ButtonClickListener leftOnClickListener,
                                                         ButtonClickListener rightOnClickListener) {
        ConfirmDialog.Builder builder = new ConfirmDialog.Builder(context)
                .setTitleMsg(title)
                .setContentMsg(message)
                .setLeftText(leftTxt)
                .setRightText(rightTxt)
                .setRightListener(rightOnClickListener)
                .setLeftListener(leftOnClickListener)
                .setListener();
        return builder;
    }

    public static ConfirmDialog.Builder getConfirmDialogWithoutContent(Context context, String title, String leftTxt,
                                                                       String rightTxt,
                                                                       ButtonClickListener leftOnClickListener,
                                                                       ButtonClickListener rightOnClickListener) {
        ConfirmDialog.Builder builder = new ConfirmDialog.Builder(context)
                .setTitleMsg(title)
                .setContentVisible(View.GONE)
                .setLeftText(leftTxt)
                .setRightText(rightTxt)
                .setLeftListener(leftOnClickListener)
                .setRightListener(rightOnClickListener)
                .setListener();
        return builder;
    }

    public static SelectDialog.Builder getSelectDialog(Context context, String[] arrays, SelectDialog
            .ISelectItemListener onClickListener) {
        SelectDialog.Builder builder = new SelectDialog.Builder(context);
        builder.setSingleChoiceItems(arrays, onClickListener);
        return builder;
    }

    public static ConfirmDialog showDialog(Context mContext, String msg) {
        ConfirmDialog dialog = new ConfirmDialog(mContext, R.style.CustomDialog, msg);
        return dialog;
    }

    /***
     * 获取一个耗时等待对话框
     *
     * @param context
     * @param message
     * @return
     */
    public static ProgressDialog getWaitDialog(Context context, String message) {
        ProgressDialog waitDialog = new ProgressDialog(context);
        if (!TextUtils.isEmpty(message)) {
            waitDialog.setMessage(message);
        }
        return waitDialog;
    }

    /***
     * 获取一个信息对话框，注意需要自己手动调用show方法显示
     *
     * @param context
     * @param message
     * @param onClickListener
     * @return
     */
    public static AlertDialog.Builder getMessageDialog(Context context, String message, DialogInterface
            .OnClickListener onClickListener) {
        AlertDialog.Builder builder = getDialog(context);
        builder.setMessage(message);
        builder.setPositiveButton("确定", onClickListener);
        return builder;
    }

    public static AlertDialog.Builder getMessageDialog(Context context, String message, DialogInterface
            .OnDismissListener dismissListener) {
        AlertDialog.Builder builder = getDialog(context);
        builder.setMessage(message);
        builder.setOnDismissListener(dismissListener);
        builder.setPositiveButton("确定", null);
        return builder;
    }

    public static AlertDialog.Builder getMessageDialog(Context context, String message) {
        AlertDialog.Builder builder = getDialog(context);
        builder.setMessage(message);
        builder.setPositiveButton("确定", null);
        return builder;
    }

    public static AlertDialog.Builder getMessageDialog(Context context, String message, String title) {
        AlertDialog.Builder builder = getDialog(context);
        builder.setMessage(message);
        builder.setTitle(title);
        builder.setPositiveButton("确定", null);
        return builder;
    }

    //    public static AlertDialog.Builder getMessageDialog(Context context, String message, String title, String
    // leftTxt, String rightTxt, DialogInterface.OnClickListener onClickListener) {
    //        AlertDialog.Builder builder = getDialog(context);
    //        builder.setMessage(Html.fromHtml(message));
    //        builder.setTitle(title);
    //        builder.setPositiveButton(rightTxt, onClickListener);
    //        builder.setNegativeButton(leftTxt, null);
    //        return builder;
    //    }

    public static AlertDialog.Builder getMessageDialog(Context context, String message, String title, String leftTxt,
                                                       String rightTxt, DialogInterface.OnClickListener
                                                               onOkClickListener, DialogInterface.OnClickListener
                                                               onCancleClickListener) {
        AlertDialog.Builder builder = getDialog(context);
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setPositiveButton(rightTxt, onOkClickListener);
        builder.setNegativeButton(leftTxt, onCancleClickListener);
        return builder;
    }

    public static AlertDialog.Builder getSelectDialog(Context context, String title, String[] arrays, DialogInterface
            .OnClickListener onClickListener) {
        AlertDialog.Builder builder = getDialog(context);
        builder.setItems(arrays, onClickListener);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);
        }
        //        builder.setPositiveButton("取消", null);
        return builder;
    }

    public static AlertDialog.Builder getSelectDialog(Context context, String[] arrays, DialogInterface
            .OnClickListener onClickListener) {
        return getSelectDialog(context, "", arrays, onClickListener);
    }

    public static AlertDialog.Builder getSingleChoiceDialog(Context context, String title, String[] arrays, int
            selectIndex, DialogInterface.OnClickListener onClickListener) {
        AlertDialog.Builder builder = getDialog(context);
        builder.setSingleChoiceItems(arrays, selectIndex, onClickListener);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);
        }
        builder.setNegativeButton("取消", null);
        builder.setPositiveButton("确定", null);
        



        return builder;
    }

    public static AlertDialog.Builder getSingleChoiceDialog(Context context, String[] arrays, int selectIndex,
                                                            DialogInterface.OnClickListener onClickListener) {
        return getSingleChoiceDialog(context, "", arrays, selectIndex, onClickListener);
    }
}
